gdk: store the visual in the GdkWindowObject
authorBenjamin Otte <otte@redhat.com>
Sat, 28 Aug 2010 23:05:59 +0000 (01:05 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 26 Sep 2010 13:11:32 +0000 (15:11 +0200)
gdk/gdkinternals.h
gdk/gdkoffscreenwindow.c
gdk/gdkwindow.c
gdk/quartz/gdkwindow-quartz.c
gdk/win32/gdkwindow-win32.c
gdk/x11/gdkwindow-x11.c

index 80ea0e1443236096dc1a82349a18dab1be843aa1..8e15d8e7ce7589419b8b6ca411e778c814483fea 100644 (file)
@@ -191,6 +191,7 @@ struct _GdkWindowObject
   GdkDrawable *impl; /* window-system-specific delegate object */  
   
   GdkWindowObject *parent;
+  GdkVisual *visual;
 
   gpointer user_data;
 
@@ -324,7 +325,6 @@ cairo_surface_t * _gdk_drawable_create_cairo_surface (GdkDrawable *drawable,
 void       _gdk_window_impl_new          (GdkWindow      *window,
                                          GdkWindow      *real_parent,
                                          GdkScreen      *screen,
-                                         GdkVisual      *visual,
                                          GdkEventMask    event_mask,
                                           GdkWindowAttr  *attributes,
                                           gint            attributes_mask);
@@ -555,7 +555,6 @@ GdkWindow *_gdk_window_get_input_window_for_event (GdkWindow *native_window,
 GType gdk_offscreen_window_get_type (void);
 void       _gdk_offscreen_window_new                 (GdkWindow     *window,
                                                      GdkScreen     *screen,
-                                                     GdkVisual     *visual,
                                                      GdkWindowAttr *attributes,
                                                      gint           attributes_mask);
 
index e231f62a3f82a7dc91938a177e4c258737336b96..37cf41b361a7789617d9f2fd9c9bee9aef7dfb1f 100644 (file)
@@ -175,7 +175,6 @@ gdk_offscreen_window_get_visual (GdkDrawable    *drawable)
 void
 _gdk_offscreen_window_new (GdkWindow     *window,
                           GdkScreen     *screen,
-                          GdkVisual     *visual,
                           GdkWindowAttr *attributes,
                           gint           attributes_mask)
 {
@@ -202,13 +201,13 @@ _gdk_offscreen_window_new (GdkWindow     *window,
     offscreen->colormap = g_object_ref (attributes->colormap);
   else
     {
-      if (gdk_screen_get_system_visual (screen) == visual)
+      if (gdk_screen_get_system_visual (screen) == private->visual)
        {
          offscreen->colormap = gdk_screen_get_system_colormap (screen);
          g_object_ref (offscreen->colormap);
        }
       else
-       offscreen->colormap = gdk_colormap_new (visual, FALSE);
+       offscreen->colormap = gdk_colormap_new (private->visual, FALSE);
     }
 
   offscreen->surface = gdk_window_create_similar_surface ((GdkWindow *)private->parent,
index d77416a93a8d83cb34b25c1489d2148703702760..6e8917f2a75d65ed81d22722b41a42f5072d733a 100644 (file)
@@ -1257,7 +1257,6 @@ gdk_window_new (GdkWindow     *parent,
   GdkWindow *window;
   GdkWindowObject *private;
   GdkScreen *screen;
-  GdkVisual *visual;
   int x, y;
   gboolean native;
   GdkEventMask event_mask;
@@ -1367,16 +1366,16 @@ gdk_window_new (GdkWindow     *parent,
     }
 
   if (attributes_mask & GDK_WA_VISUAL)
-    visual = attributes->visual;
+    private->visual = attributes->visual;
   else
-    visual = gdk_screen_get_system_visual (screen);
+    private->visual = gdk_screen_get_system_visual (screen);
 
   private->event_mask = attributes->event_mask;
 
   if (attributes->wclass == GDK_INPUT_OUTPUT)
     {
       private->input_only = FALSE;
-      private->depth = visual->depth;
+      private->depth = private->visual->depth;
 
       /* XXX: Cache this somehow? */
       private->background = cairo_pattern_create_rgb (0, 0, 0);
@@ -1402,7 +1401,7 @@ gdk_window_new (GdkWindow     *parent,
 
   if (gdk_window_is_offscreen (private))
     {
-      _gdk_offscreen_window_new (window, screen, visual, attributes, attributes_mask);
+      _gdk_offscreen_window_new (window, screen, attributes, attributes_mask);
       private->impl_window = private;
     }
   else if (native)
@@ -1410,7 +1409,7 @@ gdk_window_new (GdkWindow     *parent,
       event_mask = get_native_event_mask (private);
 
       /* Create the impl */
-      _gdk_window_impl_new (window, real_parent, screen, visual, event_mask, attributes, attributes_mask);
+      _gdk_window_impl_new (window, real_parent, screen, event_mask, attributes, attributes_mask);
       private->impl_window = private;
 
       /* This will put the native window topmost in the native parent, which may
@@ -1774,7 +1773,6 @@ gdk_window_ensure_native (GdkWindow *window)
   GdkWindowObject *impl_window;
   GdkDrawable *new_impl, *old_impl;
   GdkScreen *screen;
-  GdkVisual *visual;
   GdkWindowAttr attributes;
   GdkWindowObject *above;
   GList listhead;
@@ -1809,13 +1807,12 @@ gdk_window_ensure_native (GdkWindow *window)
   gdk_window_drop_cairo_surface (private);
 
   screen = gdk_drawable_get_screen (window);
-  visual = gdk_drawable_get_visual (window);
 
   attributes.colormap = gdk_drawable_get_colormap (window);
 
   old_impl = private->impl;
   _gdk_window_impl_new (window, (GdkWindow *)private->parent,
-                       screen, visual,
+                       screen,
                        get_native_event_mask (private),
                        &attributes, GDK_WA_COLORMAP);
   new_impl = private->impl;
index 8844034b07f770433afd82c23e1f89e48277869f..6da0f4d8d175ec3a9492be3d8b35dca42ce03bd5 100644 (file)
@@ -802,7 +802,6 @@ void
 _gdk_window_impl_new (GdkWindow     *window,
                      GdkWindow     *real_parent,
                      GdkScreen     *screen,
-                     GdkVisual     *visual,
                      GdkEventMask   event_mask,
                      GdkWindowAttr *attributes,
                      gint           attributes_mask)
@@ -843,19 +842,19 @@ _gdk_window_impl_new (GdkWindow     *window,
        }
       else
        {
-         if (visual == gdk_screen_get_system_visual (_gdk_screen))
+         if (private->visual == gdk_screen_get_system_visual (_gdk_screen))
            {
              draw_impl->colormap = gdk_screen_get_system_colormap (_gdk_screen);
              g_object_ref (draw_impl->colormap);
            }
-         else if (visual == gdk_screen_get_rgba_visual (_gdk_screen))
+         else if (private->visual == gdk_screen_get_rgba_visual (_gdk_screen))
            {
              draw_impl->colormap = gdk_screen_get_rgba_colormap (_gdk_screen);
              g_object_ref (draw_impl->colormap);
            }
          else
            {
-             draw_impl->colormap = gdk_colormap_new (visual, FALSE);
+             draw_impl->colormap = gdk_colormap_new (private->visual, FALSE);
            }
        }
     }
@@ -1043,6 +1042,7 @@ _gdk_windowing_window_init (void)
   private = (GdkWindowObject *)_gdk_root;
   private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
   private->impl_window = private;
+  private->visual = gdk_screen_get_system_visual (_gdk_screen);
 
   impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (_gdk_root)->impl);
 
index 0ec688b25b98927cdcde99b1ab712293809f8e52..69be5aab74445539af6003a0f58cb5f3219cb6a5 100644 (file)
@@ -236,6 +236,7 @@ _gdk_windowing_window_init (GdkScreen *screen)
   private = (GdkWindowObject *)_gdk_root;
   private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
   private->impl_window = private;
+  private->visual = gdk_screen_get_system_visual (screen);
 
   draw_impl = GDK_DRAWABLE_IMPL_WIN32 (private->impl);
   
@@ -428,7 +429,6 @@ void
 _gdk_window_impl_new (GdkWindow     *window,
                      GdkWindow     *real_parent,
                      GdkScreen     *screen,
-                     GdkVisual     *visual,
                      GdkEventMask   event_mask,
                      GdkWindowAttr *attributes,
                      gint           attributes_mask)
@@ -486,7 +486,6 @@ _gdk_window_impl_new (GdkWindow     *window,
       dwExStyle = 0;
 
       private->input_only = FALSE;
-      private->depth = visual->depth;
       
       if (attributes_mask & GDK_WA_COLORMAP)
        {
@@ -679,6 +678,7 @@ gdk_window_foreign_new_for_display (GdkDisplay      *display,
 
   window = g_object_new (GDK_TYPE_WINDOW, NULL);
   private = (GdkWindowObject *)window;
+  private->visual = gdk_screen_get_system_visual (_gdk_screen);
   private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
   impl = GDK_WINDOW_IMPL_WIN32 (private->impl);
   draw_impl = GDK_DRAWABLE_IMPL_WIN32 (private->impl);
index d62e343e7451ffa98142535da061252a35008a15..4f949717ea78aff9139698624e98a76bc5e89b33 100644 (file)
@@ -470,6 +470,7 @@ _gdk_windowing_window_init (GdkScreen * screen)
   private = (GdkWindowObject *) screen_x11->root_window;
   private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
   private->impl_window = private;
+  private->visual = gdk_screen_get_system_visual (screen);
 
   draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
   
@@ -689,7 +690,6 @@ void
 _gdk_window_impl_new (GdkWindow     *window,
                      GdkWindow     *real_parent,
                      GdkScreen     *screen,
-                     GdkVisual     *visual,
                      GdkEventMask   event_mask,
                      GdkWindowAttr *attributes,
                      gint           attributes_mask)
@@ -728,7 +728,7 @@ _gdk_window_impl_new (GdkWindow     *window,
 
   xattributes_mask = 0;
 
-  xvisual = ((GdkVisualPrivate*) visual)->xvisual;
+  xvisual = ((GdkVisualPrivate*) private->visual)->xvisual;
   
   if (attributes_mask & GDK_WA_NOREDIR)
     {
@@ -770,14 +770,14 @@ _gdk_window_impl_new (GdkWindow     *window,
         }
       else
        {
-         if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) ==  xvisual)
+         if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) == xvisual)
             {
              draw_impl->colormap = gdk_screen_get_system_colormap (screen);
               g_object_ref (draw_impl->colormap);
             }
          else
             {
-              draw_impl->colormap = gdk_colormap_new (visual, FALSE);
+              draw_impl->colormap = gdk_colormap_new (private->visual, FALSE);
             }
        }
       
@@ -917,6 +917,7 @@ GdkWindow *
 gdk_window_foreign_new_for_display (GdkDisplay     *display,
                                    GdkNativeWindow anid)
 {
+  GdkScreen *screen;
   GdkWindow *window;
   GdkWindowObject *private;
   GdkWindowImplX11 *impl;
@@ -950,16 +951,20 @@ gdk_window_foreign_new_for_display (GdkDisplay     *display,
   if (children)
     XFree (children);
   
+  screen = _gdk_x11_display_screen_for_xrootwin (display, root);
+
   window = g_object_new (GDK_TYPE_WINDOW, NULL);
 
   private = (GdkWindowObject *) window;
   private->impl = g_object_new (_gdk_window_impl_get_type (), NULL);
   private->impl_window = private;
+  private->visual = gdk_x11_screen_lookup_visual (screen,
+                                                  XVisualIDFromVisual (attrs.visual));
 
   impl = GDK_WINDOW_IMPL_X11 (private->impl);
   draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
   draw_impl->wrapper = GDK_DRAWABLE (window);
-  draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
+  draw_impl->screen = screen;
   
   private->parent = gdk_xid_table_lookup_for_display (display, parent);